<template>
    <panel-head :route="route" />
    <div class="flex" style="font-size: 16px;">
        <el-card class="card">
            <div style="height: 150px;align-items: center;display: flex;">
                <el-image style="height: 100%;" :src="avatar" />
                <span class="text1">{{user}}</span>
            </div>
            <div class="line"></div>
            <div class="permission">
                <div style="margin-bottom: 8px;"><span>当前权限：{{ control }}</span></div>
                <div><span>登录ip:{{ ip }}</span></div>
            </div>
        </el-card>
        <el-card class="card" body-style="padding: 0;">
            <div class="top">
                <div class="item">
                    <div>
                        <el-image style="max-width: 60px; max-height: 60px;background-color: #BF5A58;" src="/public/dzf.png"/>
                    </div>
                    <div class="text-top">
                        <div style="font-size: 1.5rem; font-weight: bold;"><span>{{ dzf }}</span></div>
                        <div style="font-size: 0.9rem;"><span>待支付</span></div>
                    </div>      
                </div>
                <div class="item">
                    <div>
                        <el-image style="max-width: 60px; max-height: 60px;background-color: #6C63AA;" src="/public/dfw.png"/>
                    </div>
                    <div class="text-top">
                        <div style="font-size: 1.5rem; font-weight: bold;"><span>{{ dfw }}</span></div>
                        <div style="font-size: 0.9rem;"><span>待服务</span></div>
                    </div>      
                </div>
            </div>
            <div class="top">
                <div class="item">
                    <div>
                        <el-image style="max-width: 60px; max-height: 60px;background-color: #79B8DA;" src="/public/ywc.png"/>
                    </div>
                    <div class="text-top">
                        <div style="font-size: 1.5rem; font-weight: bold;"><span>{{ ywc }}</span></div>
                        <div style="font-size: 0.9rem;"><span>已完成</span></div>
                    </div>      
                </div>
                <div class="item">
                    <div>
                        <el-image style="max-width: 60px; max-height: 60px;background-color: #7DD069;" src="/public/yqx.png"/>
                    </div>
                    <div class="text-top">
                        <div style="font-size: 1.5rem; font-weight: bold;"><span>{{ yqx }}</span></div>
                        <div style="font-size: 0.9rem;"><span>已取消</span></div>
                    </div>      
                </div>
            </div>
        </el-card>
    </div>
    <div id="charts">

    </div>
</template>

<script setup>
import { useRoute } from 'vue-router';
import {report} from '../../api';
import { onMounted,ref } from 'vue';
import * as echarts from 'echarts';

const route = useRoute()

onMounted(() => {
    type_dzf()
})

//用户名称
const user = ref()
const avatar = ref()
//用户权限
const control = ref()

//ip
const ip = ref()

//表格
const chart = ref([])
const date = ref([])
const order_number = ref([])

//订单数量
const dzf = ref()
const dfw = ref()
const ywc = ref()
const yqx = ref()
const type_dzf = () =>{
     report().then(({data}) => {
        user.value = data.data.user.user_name
        avatar.value = data.data.user.user_img
        control.value = data.data.user.permission
        console.log(user.value)
        //ip
        ip.value = data.data.user.ip
        dzf.value = data.data.types[0].num
        dfw.value = data.data.types[1].num
        ywc.value = data.data.types[2].num
        yqx.value = data.data.types[3].num
        //x轴、y轴
        chart.value = data.data.typeList
        date.value = chart.value.map(item => item.date)
        order_number.value = chart.value.map(item => item.order_sum)
        //生成图表
       
            const myChart = echarts.init(document.getElementById("charts"))
            myChart.setOption({
                title: {
                    //text: '订单数'
                },
                tooltip: {
                    trigger: 'axis',
                    axisPointer: {
                    type: 'cross',
                    label: {
                        backgroundColor: '#6a7985'
                    }
                    }
                },
                legend: {
                    data: ['已完成订单数']
                },
                toolbox: {
                    feature: {
                    saveAsImage: {}
                    }
                },
                xAxis: [
                    {
                    type: 'category',
                    boundaryGap: false,
                    data: date.value
                    }
                ],
                yAxis: [
                    {
                        splitLine:{
                            show:true
                        },
                        type: 'value'
                    }
                ],
                series: [
                    {
                        name: '已完成订单数',
                        type: 'line',
                        stack: 'Total',
                        label: {
                            show: true,
                            position: 'top'
                        },
                        emphasis: {
                            focus: 'series'
                        },
                        data: order_number.value
                    }
                ]
            })
        
    })
}



</script>

<style lang="less" scoped>
.flex{
    display: flex;
    justify-content: space-between;
    margin: 30px 5px 45px 0;
    .card{
        width: 48%;
        height: 290px;
        .top{
            height: 145px; 
            display: flex;
            .item{
                height: 150px;
                width: 50%;
                display: flex;
                align-items: center;
                justify-content: center;
                .text-top{
                    margin-left: 5px;
                }
            }
        }
    }
    .text1{
        font-size: 32px;
        font-weight: bold;
        line-height: 145px;
    }
    .line{
        width: 100%;
        height: 1px;
        border-top: solid #999 1px;
        margin-bottom: 20px;
        margin-top: 20px;
    }
    .permission{
        margin-bottom: 15px;
        color: #999;
    }
}
#charts{
    height: 400px;
    margin-top: 30px;
    margin-right: 5px;
    background-color: #fff;
}
</style>